﻿using Application.Services.Dto;
using Application.Services.Dto.Organization.Request;
using Application.Services.Dto.Organization.Response;
using Application.Services.Interface.Organization;
using Domain.Interface.Organization;
using System;
using System.Collections.Generic;
using System.Text;

namespace Application.Services.Organization
{
    public class UserAppServices : BaseAppServices, IUserAppService
    {
        public string Test()
        {
            return "OK";
        }

        public Guid CreateUser()
        {
            Guid keyId = Guid.NewGuid();
            ///创建一个领域对象，然后给对象赋值，然后保存对象
            return keyId;
        }

        public BaseResponseDto<bool> CreateUser(CreateUserDto user)
        {
            BaseResponseDto<bool> resp = new BaseResponseDto<bool>();
            IUserDomain userDomain = base.BuildUserDomain(user.Name);
            userDomain.SetIsDelete(true);

            base.UserRepository.Add(userDomain);

            resp.Result = base.SaveChanges() > 0;

            return resp;
        }

        public BaseResponseDto<FindUserResponseDto> FindUser(Guid keyId)
        {
            BaseResponseDto<FindUserResponseDto> resp = new BaseResponseDto<FindUserResponseDto>();

            IUserDomain userDomain = base.UserRepository.Find(keyId);

            if (userDomain != null)
            {
                resp.Result = new FindUserResponseDto()
                {
                    Name = userDomain.GetName()
                };
            }

            return resp;
        }

    }
}
